<%@ Page language="vb" CodeFile="addPartner.aspx.vb" Inherits="addPartner_aspx_vb" %>

<%
    rowNumber = 0
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        Over()
        strJS = ""
        strJS = strJS + "[""countryID"", ""<1""],"
        strJS = strJS + "[""partnerName"", ""==''""],"
        strJS = strJS + "[""street"", ""==''""],"
        strJS = strJS + "[""zipCode"", ""==''""],"
        strJS = strJS + "[""city"", ""==''""],"
        strJS = strJS + "[""pwd"", ""==''""],"
        strJS = strJS + "[""invoiceFee"", ""==''""],"
        strJS = strJS + "[""chooseClient"", ""<1""]"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>ADD PARTNER<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addPartner.aspx?do=save' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Country:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='countryID' id='countryID'>")
        Response.Write("<option value=''> Select country  ")
        dbOpen()
        RecSet = Conn.Execute("Select countryID, country From tblCountry")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                countryID = RecSet.Fields("countryID").Value
                country = RecSet.Fields("country").Value
                Response.Write("<option value='" & countryID & "'> " & country & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_countryID' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'>Partner:</td><td align='right'><input type='text' name='partnerName' id='partnerName' size='40' maxlength='50'></td><td><div id='error_partnerName' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' size='40' maxlength='50'></td><td><div id='error_street' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipCode' id='zipCode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td><td><div id='error_zipCode' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td><td><div id='error_city' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Partner web - password:</td><td align='right'><input type='text' name='pwd' id='pwd' size='40' maxlength='50'></td><td><div id='error_pwd' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Invoice fee:</td><td align='right'><input type='text' name='invoiceFee' id='invoiceFee' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td><td><div id='error_invoiceFee' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>Contract number prefix:</td><td align='right'><input type='text' name='contractNumberPrefix' id='contractNumberPrefix' size='40' maxlength='1'></td></tr>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Partner web - choose Lease taker:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='chooseClient' id='chooseClient'>")
        Response.Write("<option value=''> Select option  ")
        Response.Write("<option value='1'> Yes  ")
        Response.Write("<option value='2'> No  ")
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_chooseClient' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>STATISTIC<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select Count(partnerID) As partnerCount From tblPartner")
        If Not RecSet.EOF Then 
            partnerCount = RecSet.Fields("partnerCount").Value
            Response.Write("<tr bgcolor='#eeeeee'><td>Number of partners saved:</td><td align='right'>" & partnerCount & " st</td></tr>")
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then
        
        countryID = Request.Form("countryID")
        partnerName = Request.Form("partnerName")
        street = Request.Form("street")
        zipCode = Request.Form("zipCode")
        city = Request.Form("city")
        pwd = Request.Form("pwd")
        invoiceFee = Request.Form("invoiceFee")
        contractNumberPrefix = Request.Form("contractNumberPrefix")
        chooseClient = Request.Form("chooseClient")
        
        countryID = CLng(countryID)
        
        If Len(partnerName) > 0 Then
            partnerName = Trim(partnerName)
            partnerName = Replace(partnerName, "'", "")
            partnerName = Replace(partnerName, """", "")
            partnerName = Replace(partnerName, "<", "")
            partnerName = Replace(partnerName, ">", "")
            partnerName = Replace(partnerName, "=", "")
        End If
        
        If Len(street) > 0 Then
            street = Trim(street)
            street = Replace(street, "'", "")
            street = Replace(street, """", "")
            street = Replace(street, "<", "")
            street = Replace(street, ">", "")
            street = Replace(street, "=", "")
        End If
        
        If Len(zipCode) > 0 Then
            zipCode = Trim(zipCode)
            zipCode = Replace(zipCode, "'", "")
            zipCode = Replace(zipCode, """", "")
            zipCode = Replace(zipCode, "<", "")
            zipCode = Replace(zipCode, ">", "")
            zipCode = Replace(zipCode, "=", "")
        End If
        
        If Len(city) > 0 Then
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End If
        
        If Len(pwd) > 0 Then
            pwd = Trim(pwd)
            pwd = Replace(pwd, "'", "")
            pwd = Replace(pwd, """", "")
            pwd = Replace(pwd, "<", "")
            pwd = Replace(pwd, ">", "")
            pwd = Replace(pwd, "=", "")
        End If
        
        If Len(contractNumberPrefix) > 0 Then
            contractNumberPrefix = Trim(contractNumberPrefix)
            contractNumberPrefix = Replace(contractNumberPrefix, "'", "")
            contractNumberPrefix = Replace(contractNumberPrefix, """", "")
            contractNumberPrefix = Replace(contractNumberPrefix, "<", "")
            contractNumberPrefix = Replace(contractNumberPrefix, ">", "")
            contractNumberPrefix = Replace(contractNumberPrefix, "=", "")
        End If
        
        invoiceFee = CLng(invoiceFee)
        chooseClient = CLng(chooseClient)
        
        dbOpen()
            Conn.Execute("Insert Into tblPartner (countryID, partnerName, street, zipCode, city, pwd, chooseClient, invoiceFee, contractNumberPrefix) Values(" & countryID & ",'" & partnerName & "','" & street & "','" & zipCode & "','" & city & "','" & pwd & "'," & chooseClient & "," & invoiceFee & ",'" & contractNumberPrefix & "')")
        dbClose()
        
        Response.Redirect("addPartner.aspx?subDo=%20-%20SPARAD")
        
    End IF
%>
